home *** CD-ROM | disk | FTP | other *** search
/ BBS in a Box 7 / BBS in a Box - Macintosh - Volume VII (BBS in a Box) (January 1993).iso / Files / Prog / T / Think-Pascal-7.0.cpt / THINK Pascal Interfaces / Sound.p < prev    next >
Encoding:
Text File  |  1991-04-03  |  15.2 KB  |  477 lines  |  [TEXT/PJMM]

  1. {    This file has been processed by The THINK Pascal Source Converter, v1.1.    }
  2.  
  3. {}
  4. {Created: Tuesday, March 5, 1991 at 5:12 PM}
  5. {    Sound.p}
  6. {    Pascal Interface to the Macintosh Libraries}
  7. {}
  8. {        Copyright Apple Computer, Inc.    1986-1991}
  9. {        All rights reserved}
  10. {}
  11.  
  12.  
  13. {$IFC UNDEFINED UsingIncludes}
  14. {$SETC UsingIncludes := 0}
  15. {$ENDC}
  16.  
  17.  
  18. unit Sound;
  19. interface
  20.     uses
  21.         Types, OSUtils, Files;
  22.  
  23.  
  24.  
  25.  
  26.  
  27.  
  28.  
  29.  
  30.  
  31.  
  32.  
  33.  
  34.  
  35.  
  36.  
  37.  
  38.     const
  39.         swMode = -1;                                    { Sound Driver modes }
  40.         ftMode = 1;
  41.         ffMode = 0;
  42.  
  43.         synthCodeRsrc = 'snth';                         { Resource types used by Sound Manager }
  44.         soundListRsrc = 'snd ';
  45.  
  46.         twelfthRootTwo = 1.05946309434;
  47.         rate22khz = $56EE8BA3;                          { 22254.54545 in fixed-point }
  48.         rate11khz = $2B7745D1;                          { 11127.27273 in fixed-point }
  49.  
  50. { synthesizer numbers for SndNewChannel }
  51.         squareWaveSynth = 1;                            {square wave synthesizer}
  52.         waveTableSynth = 3;                             {wave table synthesizer}
  53.         sampledSynth = 5;                               {sampled sound synthesizer}
  54.  
  55. { old Sound Manager MACE synthesizer numbers }
  56.         MACE3snthID = 11;
  57.         MACE6snthID = 13;
  58.  
  59. { command numbers for SndDoCommand and SndDoImmediate }
  60.         nullCmd = 0;
  61.         initCmd = 1;
  62.         freeCmd = 2;
  63.         quietCmd = 3;
  64.         flushCmd = 4;
  65.         reInitCmd = 5;
  66.  
  67.         waitCmd = 10;
  68.         pauseCmd = 11;
  69.         resumeCmd = 12;
  70.         callBackCmd = 13;
  71.         syncCmd = 14;
  72.         emptyCmd = 15;
  73.  
  74.         tickleCmd = 20;
  75.         requestNextCmd = 21;
  76.         howOftenCmd = 22;
  77.         wakeUpCmd = 23;
  78.         availableCmd = 24;
  79.         versionCmd = 25;
  80.         totalLoadCmd = 26;
  81.         loadCmd = 27;
  82.  
  83.         scaleCmd = 30;
  84.         tempoCmd = 31;
  85.  
  86.         freqDurationCmd = 40;
  87.         restCmd = 41;
  88.         freqCmd = 42;
  89.         ampCmd = 43;
  90.         timbreCmd = 44;
  91.         getAmpCmd = 45;
  92.  
  93.         waveTableCmd = 60;
  94.         phaseCmd = 61;
  95.  
  96.         soundCmd = 80;
  97.         bufferCmd = 81;
  98.         rateCmd = 82;
  99.         continueCmd = 83;
  100.         doubleBufferCmd = 84;
  101.         getRateCmd = 85;
  102.  
  103.         sizeCmd = 90;
  104.         convertCmd = 91;
  105.  
  106.         stdQLength = 128;
  107.         dataOffsetFlag = $8000;
  108.  
  109.         waveInitChannelMask = $07;
  110.         waveInitChannel0 = $04;
  111.         waveInitChannel1 = $05;
  112.         waveInitChannel2 = $06;
  113.         waveInitChannel3 = $07;
  114.  
  115. { channel initialization parameters }
  116.         initPanMask = $0003;                            { mask for right/left pan values }
  117.         initSRateMask = $0030;                          { mask for sample rate values }
  118.         initStereoMask = $00C0;                         { mask for mono/stereo values }
  119.         initCompMask = $FF00;                           { mask for compression IDs }
  120.  
  121.         initChanLeft = $0002;                           { left stereo channel }
  122.         initChanRight = $0003;                          { right stereo channel }
  123.         initNoInterp = $0004;                           { no linear interpolation }
  124.         initNoDrop = $0008;                             { no drop-sample conversion }
  125.         initMono = $0080;                               { monophonic channel }
  126.         initStereo = $00C0;                             { stereo channel }
  127.         initMACE3 = $0300;                              { MACE 3:1 }
  128.         initMACE6 = $0400;                              { MACE 6:1 }
  129.  
  130.         initChan0 = $0004;                              { channel 0 - wave table only }
  131.         initChan1 = $0005;                              { channel 1 - wave table only }
  132.         initChan2 = $0006;                              { channel 2 - wave table only }
  133.         initChan3 = $0007;                              { channel 3 - wave table only }
  134.  
  135.         stdSH = $00;                                    { Standard sound header encode value }
  136.         extSH = $FF;                                    { Extended sound header encode value }
  137.         cmpSH = $FE;                                    { Compressed sound header encode value }
  138.  
  139.         notCompressed = 0;                              { compression ID's }
  140.         twoToOne = 1;
  141.         eightToThree = 2;
  142.         threeToOne = 3;
  143.         sixToOne = 4;
  144.  
  145.         outsideCmpSH = 0;                               { MACE constants }
  146.         insideCmpSH = 1;
  147.         aceSuccess = 0;
  148.         aceMemFull = 1;
  149.         aceNilBlock = 2;
  150.         aceBadComp = 3;
  151.         aceBadEncode = 4;
  152.         aceBadDest = 5;
  153.         aceBadCmd = 6;
  154.         sixToOnePacketSize = 8;
  155.         threeToOnePacketSize = 16;
  156.         stateBlockSize = 64;
  157.         leftOverBlockSize = 32;
  158.  
  159.         firstSoundFormat = $0001;                       { general sound format }
  160.         secondSoundFormat = $0002;                      { special sampled sound format (HyperCard) }
  161.  
  162.         dbBufferReady = $00000001;                      { double buffer is filled }
  163.         dbLastBuffer = $00000004;                       { last double buffer to play }
  164.  
  165.         sysBeepDisable = $0000;                         { SysBeep() enable flags }
  166.         sysBeepEnable = $0001;
  167.  
  168.         unitTypeNoSelection = $FFFF;                    { unitTypes for AudioSelection.unitType }
  169.         unitTypeSeconds = $0000;
  170.  
  171.     const
  172.         stdQLengthMinusOne = stdQLength - 1;
  173.         stateBlockSizeMinusOne = stateBlockSize - 1;
  174.         leftOverBlockSizeMinusOne = leftOverBlockSize - 1;
  175.  
  176.     type
  177. {            Structures for Sound Driver            }
  178.  
  179.  
  180.         FreeWave = packed array[0..30000] of Byte;
  181.  
  182.         FFSynthPtr = ^FFSynthRec;
  183.         FFSynthRec = record
  184.                 mode: INTEGER;
  185.                 count: Fixed;
  186.                 waveBytes: FreeWave;
  187.             end;
  188.  
  189.         Tone = record
  190.                 count: INTEGER;
  191.                 amplitude: INTEGER;
  192.                 duration: INTEGER;
  193.             end;
  194.  
  195.  
  196.         Tones = array[0..5000] of Tone;
  197.  
  198.         SWSynthPtr = ^SWSynthRec;
  199.         SWSynthRec = record
  200.                 mode: INTEGER;
  201.                 triplets: Tones;
  202.             end;
  203.  
  204.  
  205.         Wave = packed array[0..255] of Byte;
  206.         WavePtr = ^Wave;
  207.  
  208.         FTSndRecPtr = ^FTSoundRec;
  209.         FTSoundRec = record
  210.                 duration: INTEGER;
  211.                 sound1Rate: Fixed;
  212.                 sound1Phase: LONGINT;
  213.                 sound2Rate: Fixed;
  214.                 sound2Phase: LONGINT;
  215.                 sound3Rate: Fixed;
  216.                 sound3Phase: LONGINT;
  217.                 sound4Rate: Fixed;
  218.                 sound4Phase: LONGINT;
  219.                 sound1Wave: WavePtr;
  220.                 sound2Wave: WavePtr;
  221.                 sound3Wave: WavePtr;
  222.                 sound4Wave: WavePtr;
  223.             end;
  224.  
  225.         FTSynthPtr = ^FTSynthRec;
  226.         FTSynthRec = record
  227.                 mode: INTEGER;
  228.                 sndRec: FTSndRecPtr;
  229.             end;
  230.  
  231. {            Structures for Sound Manager            }
  232.  
  233.         SndCommand = packed record
  234.                 cmd: INTEGER;
  235.                 param1: INTEGER;
  236.                 param2: LONGINT;
  237.             end;
  238.  
  239.  
  240.         Time = LONGINT;                                 { in half milliseconds }
  241.  
  242.  
  243.         SndChannelPtr = ^SndChannel;
  244.         SndChannel = packed record
  245.                 nextChan: SndChannelPtr;
  246.                 firstMod: Ptr;                              { reserved for the Sound Manager }
  247.                 callBack: ProcPtr;
  248.                 userInfo: LONGINT;
  249.                 wait: Time;                                 { The following is for internal Sound Manager use only.}
  250.                 cmdInProgress: SndCommand;
  251.                 flags: INTEGER;
  252.                 qLength: INTEGER;
  253.                 qHead: INTEGER;                             { next spot to read or -1 if empty }
  254.                 qTail: INTEGER;                             { next spot to write = qHead if full }
  255.                 queue: array[0..stdQLengthMinusOne] of SndCommand;
  256.             end;
  257.  
  258. { MACE structures }
  259.         StateBlockPtr = ^StateBlock;
  260.         StateBlock = record
  261.                 stateVar: array[0..stateBlockSizeMinusOne] of INTEGER;
  262.             end;
  263.  
  264.         LeftOverBlockPtr = ^LeftOverBlock;
  265.         LeftOverBlock = record
  266.                 count: LONGINT;
  267.                 sampleArea: packed array[0..leftOverBlockSizeMinusOne] of Byte;
  268.             end;
  269.  
  270.         ModRef = record
  271.                 modNumber: INTEGER;
  272.                 modInit: LONGINT;
  273.             end;
  274.  
  275.         SndListPtr = ^SndListResource;
  276.         SndListResource = record
  277.                 format: INTEGER;
  278.                 numModifiers: INTEGER;
  279.                 modifierPart: array[0..0] of ModRef;       {This is a variable length array}
  280.                 numCommands: INTEGER;
  281.                 commandPart: array[0..0] of SndCommand;    {This is a variable length array}
  282.                 dataPart: packed array[0..0] of Byte;      {This is a variable length array}
  283.             end;
  284.  
  285.         SoundHeaderPtr = ^SoundHeader;
  286.         SoundHeader = packed record
  287.                 samplePtr: Ptr;                             { if NIL then samples are in sampleArea }
  288.                 length: LONGINT;                            { length of sound in bytes }
  289.                 sampleRate: Fixed;                          { sample rate for this sound }
  290.                 loopStart: LONGINT;                         { start of looping portion }
  291.                 loopEnd: LONGINT;                           { end of looping portion }
  292.                 encode: Byte;                               { header encoding }
  293.                 baseFrequency: Byte;                        { baseFrequency value }
  294.                 sampleArea: packed array[0..0] of Byte;
  295.             end;
  296.  
  297.  
  298.         CmpSoundHeaderPtr = ^CmpSoundHeader;
  299.         CmpSoundHeader = packed record
  300.                 samplePtr: Ptr;                             { if nil then samples are in sample area }
  301.                 numChannels: LONGINT;                       { number of channels i.e. mono = 1 }
  302.                 sampleRate: Fixed;                          { sample rate in Apples Fixed point representation }
  303.                 loopStart: LONGINT;                         { loopStart of sound before compression }
  304.                 loopEnd: LONGINT;                           { loopEnd of sound before compression }
  305.                 encode: Byte;                               { data structure used , stdSH, extSH, or cmpSH }
  306.                 baseFrequency: Byte;                        { same meaning as regular SoundHeader }
  307.                 numFrames: LONGINT;                         { length in frames ( packetFrames or sampleFrames ) }
  308.                 AIFFSampleRate: extended;                   { IEEE sample rate }
  309.                 markerChunk: Ptr;                           { sync track }
  310.                 futureUse1: Ptr;                            { reserved by Apple }
  311.                 futureUse2: Ptr;                            { reserved by Apple }
  312.                 stateVars: StateBlockPtr;                   { pointer to State Block }
  313.                 leftOverSamples: LeftOverBlockPtr;          { used to save truncated samples between compression calls }
  314.                 compressionID: INTEGER;                     { 0 means no compression, non zero means compressionID }
  315.                 packetSize: INTEGER;                        { number of bits in compressed sample packet }
  316.                 snthID: INTEGER;                            { resource ID of Sound Manager snth that contains NRT C/E }
  317.                 sampleSize: INTEGER;                        { number of bits in non-compressed sample }
  318.                 sampleArea: packed array[0..0] of Byte;    { space for when samples follow directly }
  319.             end;
  320.  
  321.         ExtSoundHeaderPtr = ^ExtSoundHeader;
  322.         ExtSoundHeader = packed record
  323.                 samplePtr: Ptr;                             { if nil then samples are in sample area }
  324.                 numChannels: LONGINT;                       { number of channels,  ie mono = 1 }
  325.                 sampleRate: Fixed;                          { sample rate in Apples Fixed point representation }
  326.                 loopStart: LONGINT;                         { same meaning as regular SoundHeader }
  327.                 loopEnd: LONGINT;                           { same meaning as regular SoundHeader }
  328.                 encode: Byte;                               { data structure used , stdSH, extSH, or cmpSH }
  329.                 baseFrequency: Byte;                        { same meaning as regular SoundHeader }
  330.                 numFrames: LONGINT;                         { length in total number of frames }
  331.                 AIFFSampleRate: extended;                   { IEEE sample rate }
  332.                 markerChunk: Ptr;                           { sync track }
  333.                 instrumentChunks: Ptr;                      { AIFF instrument chunks }
  334.                 AESRecording: Ptr;
  335.                 sampleSize: INTEGER;                        { number of bits in sample }
  336.                 futureUse1: INTEGER;                        { reserved by Apple }
  337.                 futureUse2: LONGINT;                        { reserved by Apple }
  338.                 futureUse3: LONGINT;                        { reserved by Apple }
  339.                 futureUse4: LONGINT;                        { reserved by Apple }
  340.                 sampleArea: packed array[0..0] of Byte;    { space for when samples follow directly }
  341.             end;
  342.  
  343.         ConversionBlockPtr = ^ConversionBlock;
  344.         ConversionBlock = record
  345.                 destination: INTEGER;
  346.                 unused: INTEGER;
  347.                 inputPtr: CmpSoundHeaderPtr;
  348.                 outputPtr: CmpSoundHeaderPtr;
  349.             end;
  350.  
  351.         SMStatusPtr = ^SMStatus;
  352.         SMStatus = packed record
  353.                 smMaxCPULoad: INTEGER;
  354.                 smNumChannels: INTEGER;
  355.                 smCurCPULoad: INTEGER;
  356.             end;
  357.  
  358.         SCStatusPtr = ^SCStatus;
  359.         SCStatus = record
  360.                 scStartTime: Fixed;
  361.                 scEndTime: Fixed;
  362.                 scCurrentTime: Fixed;
  363.                 scChannelBusy: BOOLEAN;
  364.                 scChannelDisposed: BOOLEAN;
  365.                 scChannelPaused: BOOLEAN;
  366.                 scUnused: BOOLEAN;
  367.                 scChannelAttributes: LONGINT;
  368.                 scCPULoad: LONGINT;
  369.             end;
  370.  
  371.         AudioSelectionPtr = ^AudioSelection;
  372.         AudioSelection = packed record
  373.                 unitType: LONGINT;
  374.                 selStart: Fixed;
  375.                 selEnd: Fixed;
  376.             end;
  377.  
  378.         SndDoubleBufferPtr = ^SndDoubleBuffer;
  379.         SndDoubleBuffer = packed record
  380.                 dbNumFrames: LONGINT;
  381.                 dbFlags: LONGINT;
  382.                 dbUserInfo: array[0..1] of LONGINT;
  383.                 dbSoundData: packed array[0..0] of Byte;
  384.             end;
  385.  
  386.         SndDoubleBufferHeaderPtr = ^SndDoubleBufferHeader;
  387.         SndDoubleBufferHeader = packed record
  388.                 dbhNumChannels: INTEGER;
  389.                 dbhSampleSize: INTEGER;
  390.                 dbhCompressionID: INTEGER;
  391.                 dbhPacketSize: INTEGER;
  392.                 dbhSampleRate: Fixed;
  393.                 dbhBufferPtr: array[0..1] of SndDoubleBufferPtr;
  394.                 dbhDoubleBack: ProcPtr;
  395.             end;
  396.  
  397.  
  398.     function SndDoCommand (chan: SndChannelPtr; cmd: SndCommand; noWait: BOOLEAN): OSErr;
  399.     inline
  400.         $A803;
  401.     function SndDoImmediate (chan: SndChannelPtr; cmd: SndCommand): OSErr;
  402.     inline
  403.         $A804;
  404.     function SndNewChannel (var chan: SndChannelPtr; synth: INTEGER; init: LONGINT; userRoutine: ProcPtr): OSErr;
  405.     inline
  406.         $A807;
  407.     function SndDisposeChannel (chan: SndChannelPtr; quietNow: BOOLEAN): OSErr;
  408.     inline
  409.         $A801;
  410.     function SndPlay (chan: SndChannelPtr; sndHdl: Handle; async: BOOLEAN): OSErr;
  411.     inline
  412.         $A805;
  413.     function SndAddModifier (chan: SndChannelPtr; modifier: ProcPtr; id: INTEGER; init: LONGINT): OSErr;
  414.     inline
  415.         $A802;
  416.     function SndControl (id: INTEGER; var cmd: SndCommand): OSErr;
  417.     inline
  418.         $A806;
  419.  
  420.     procedure SetSoundVol (level: INTEGER);
  421.     procedure GetSoundVol (var level: INTEGER);
  422.     procedure StartSound (synthRec: Ptr; numBytes: LONGINT; completionRtn: ProcPtr);
  423.     procedure StopSound;
  424.     function SoundDone: BOOLEAN;
  425.  
  426.     function SndSoundManagerVersion: NumVersion;
  427.     inline
  428.         $203C, $000C, $0008, $A800;
  429.     function SndStartFilePlay (chan: SndChannelPtr; fRefNum: INTEGER; resNum: INTEGER; bufferSize: LONGINT; theBuffer: Ptr; theSelection: AudioSelectionPtr; theCompletion: ProcPtr; async: BOOLEAN): OSErr;
  430.     inline
  431.         $203C, $0D00, $0008, $A800;
  432.     function SndPauseFilePlay (chan: SndChannelPtr): OSErr;
  433.     inline
  434.         $203C, $0204, $0008, $A800;
  435.     function SndStopFilePlay (chan: SndChannelPtr; async: BOOLEAN): OSErr;
  436.     inline
  437.         $203C, $0308, $0008, $A800;
  438.     function SndChannelStatus (chan: SndChannelPtr; theLength: INTEGER; theStatus: SCStatusPtr): OSErr;
  439.     inline
  440.         $203C, $0010, $0008, $A800;
  441.     function SndManagerStatus (theLength: INTEGER; theStatus: SMStatusPtr): OSErr;
  442.     inline
  443.         $203C, $0014, $0008, $A800;
  444.     procedure SndGetSysBeepState (var sysBeepState: INTEGER);
  445.     inline
  446.         $203C, $0018, $0008, $A800;
  447.     function SndSetSysBeepState (sysBeepState: INTEGER): OSErr;
  448.     inline
  449.         $203C, $001C, $0008, $A800;
  450.     function SndPlayDoubleBuffer (chan: SndChannelPtr; theParams: SndDoubleBufferHeaderPtr): OSErr;
  451.     inline
  452.         $203C, $0020, $0008, $A800;
  453.  
  454.     function MACEVersion: NumVersion;
  455.     inline
  456.         $203C, $0000, $0010, $A800;
  457.     procedure Comp3to1 (inBuffer: Ptr; outBuffer: Ptr; cnt: LONGINT; inState: Ptr; outState: Ptr; numChannels: LONGINT; whichChannel: LONGINT);
  458.     inline
  459.         $203C, $0004, $0010, $A800;
  460.     procedure Exp1to3 (inBuffer: Ptr; outBuffer: Ptr; cnt: LONGINT; inState: Ptr; outState: Ptr; numChannels: LONGINT; whichChannel: LONGINT);
  461.     inline
  462.         $203C, $0008, $0010, $A800;
  463.     procedure Comp6to1 (inBuffer: Ptr; outBuffer: Ptr; cnt: LONGINT; inState: Ptr; outState: Ptr; numChannels: LONGINT; whichChannel: LONGINT);
  464.     inline
  465.         $203C, $000C, $0010, $A800;
  466.     procedure Exp1to6 (inBuffer: Ptr; outBuffer: Ptr; cnt: LONGINT; inState: Ptr; outState: Ptr; numChannels: LONGINT; whichChannel: LONGINT);
  467.     inline
  468.         $203C, $0010, $0010, $A800;
  469.  
  470.  
  471.     { UsingSound }
  472.  
  473.  
  474. implementation
  475. end.
  476.  
  477.